<template>
    <div>
        <el-row :gutter="20">
            <el-col :span="6" v-for="area in areas" :key="area.id">
                <area-card class="area-card" :area="area"></area-card>
            </el-col>
        </el-row>
        <el-row>
            <el-col :span="18" :offset="3">
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="pageInfo.page"
                    :page-sizes="pageInfo.sizes"
                    :page-size="pageInfo.size"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="pageInfo.total">
                </el-pagination>
            </el-col>
        </el-row>
    </div>
</template>

<script>
    import { mapActions } from 'vuex'
    import AreaCard from '@/components/area/AreaCard'

    export default {
        name: 'commonArea',
        components: {
            AreaCard
        },
        data () {
            return {
                pageInfo: {
                    page: 1,
                    size: 20,
                    total: 0,
                    sizes: [20, 50, 100, 200, 300, 400]
                },
                areas: []
            }
        },
        mounted () {
            this.obtainAreas()
        },
        methods: {
            handleSizeChange (val) {
                this.pageInfo.size = val
                this.obtainAreas()
            },
            handleCurrentChange (val) {
                this.pageInfo.page = val
                this.obtainAreas()
            },
            ...mapActions('area', {
                pageAreaAction: 'pageArea',
                currentAttentionAreasAction: 'currentAttentionAreas'
            }),
            obtainAreas () {
                this.pageAreaAction(this.pageInfo).then(data => {
                    this.areas = data.data.records
                    this.pageInfo.total = data.data.total
                    this.pageInfo.page = data.data.pages
                })
            }
        }
    }
</script>

<style lang="scss" scoped>
    .area-card {
        margin: 20px 0;
    }
</style>
